<?php

namespace App\Containers\AppSection\Authentication\Claims;

use App\Containers\AppSection\User\Tasks\FindUserByIdTask;
use App\Ship\Exceptions\AuthenticationException;

class BanClaim
{
    public function handle($token, $next)
    {
        $user = app(FindUserByIdTask::class)->run($token->getUserIdentifier());

        if ($user->isBanned()) {
            throw new AuthenticationException(__('ship::auth.ban'));
        }

        return $next($token);
    }
}
